package Controller;

import Model.Map;
import Model.Tile;
import View.*;

import java.awt.*;

public class Main 
{
	private static ConfigFrame configFrame;
    private static MapFrame mapFrame;
    private static MapGenerator mapGenerator;
    private static Map myMap;

	public static void startConfig()
	{
		configFrame = new ConfigFrame();
        configFrame.showStartScreen();
	}
	
	public static void main(String args[])
	{
		Main.startConfig();
	}

    /**
     * This is called when the 'generate' button is pressed on the config screen. It passes in the values chosen by the
     * user which are then used to make a custom map generator around these conditions.
     * @param snowHeight  the minimum height for the snow biome. everything above this will be snow
     * @param mountainHeight  the minimum height for the mountain biome. everything above this will be mountain unless
     *                        it's already snow.
     * @param plainsHeight   the minimum height for the plains biome. everything between this and mountainHeight will
     *                       be plains
     * @param plainsAmount   represents the prevalence of plains, 0 for low, 1 for medium, 2 for high. higher values
     *                       mean that other biomes will not expand into plains as much.
     * @param desertAmount   represents the prevalence of deserts, 0 for low, 1 for medium, 2 for high. higher values
     *                       mean more desert pivots and/or deserts expand more.
     * @param forestAmount   represents the prevalence of forests. higher values mean that forests spread farther away
     *                       from rivers.
     * @param riverAmount    represents the prevalence of rivers. higher values mean more river pivots.
     * @param mountainAmount represents the prevalence of mountains and hills. higher values mean more mountain pivots
     */
    public static void setUpMapGenerator(int snowHeight, int mountainHeight, int plainsHeight, int oceanHeight, int minHeight, int plainsAmount, int desertAmount, int forestAmount, int riverAmount, int mountainAmount)
    {
        mapGenerator = new MapGenerator( snowHeight,  mountainHeight,  plainsHeight, oceanHeight, minHeight,  plainsAmount,  desertAmount,  forestAmount,  riverAmount,  mountainAmount);
        configFrame.dispose();

        mapFrame = new MapFrame();
        mapFrame.showMapPanel();
        myMap = mapGenerator.generate();
        mapFrame.drawMap(sendMapToView());
    }

    public static Color[][] sendMapToView()
    {
        Color[][] colors = new Color[128][72];
        for(int i = 0; i < 128; i++)
        {
            for(int j = 0; j < 72; j++)
            {
                //Tile t = myMap.tiles.get(new Point(i,j));
                Tile t = myMap.tiles[i][j];
                if(t != null)
                {
                    //int alpha = 255 - (int)t.getHeight();
                    Color base = t.getBiome().getColor();
                    colors[i][j] = new Color(base.getRed(),base.getGreen(),base.getBlue(), t.alpha);
                    //colors[i][j] = t.getBiome().getColor();

                    //System.out.println(colors[i][j].getRed()+" "+colors[i][j].getGreen()+ " "+ colors[i][j].getBlue());
                }
                else
                {
                    colors[i][j] = Tile.Biome.OCEAN.getColor();
                    //colors[i][j] = new Color(255,255,255,255);
                }
            }
        }
        return colors;
    }


}
